#ifndef __BSP_IIC_H
#define __BSP_IIC_H

#include "ch32f10x.h"
#include "stdio.h"	
#include "stdbool.h"	

#define I2C_Delay() 			Delay_Us(2)
#define I2C_DelayHalf() 	Delay_Us(1)

#define SCL_H i2c->SCL_GPIOx->BSHR = i2c->SCL_Pin
#define SCL_L i2c->SCL_GPIOx->BCR = i2c->SCL_Pin
  
   
#define SDA_H i2c->SDA_GPIOx->BSHR = i2c->SDA_Pin 
#define SDA_L i2c->SDA_GPIOx->BCR = i2c->SDA_Pin

#define SCL_read 	(i2c->SCL_GPIOx->INDR  & i2c->SCL_Pin)
#define SDA_read 	(i2c->SDA_GPIOx->INDR  & i2c->SDA_Pin)


typedef struct
{
	GPIO_TypeDef * SCL_GPIOx;
	GPIO_TypeDef * SDA_GPIOx;
	uint16_t SCL_Pin;
	uint16_t SDA_Pin;
} I2C;

extern I2C *I2C_1;

void I2C_GPIO_Config(void);

bool I2C_Start(I2C * i2c);
bool I2C_Stop(I2C * i2c);
void I2C_Ack(I2C * i2c);
void I2C_NoAck(I2C * i2c);
bool I2C_WaitAck(I2C * i2c);
void I2C_SendByte(I2C * i2c, uint8_t SendByte);
uint8_t I2C_RadeByte(I2C * i2c);
bool I2C_Write_REG(I2C * i2c, uint8_t SlaveAddress,uint8_t REG_Address, uint8_t REG_data);
uint8_t I2C_Read_REG(I2C * i2c, uint8_t SlaveAddress,uint8_t REG_Address);
bool I2C_Write_DataNaddr(I2C * i2c, uint8_t REG_Address, uint8_t data);

#endif
